﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Common;

public partial class ModifyTopic : System.Web.UI.Page
{
    Topic topic = new Topic();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null || Session["UserName"].ToString() == "Guest")
        {
            Response.Redirect("Login.aspx");
        }
        if (!Page.IsPostBack)
        {
            DbDataReader dr = topic.GetTopicDetail(Convert.ToInt32(Request.QueryString["TopicID"]));
            if (dr.Read())
            {
                txtTopicTitle.Text = dr["TopicTitle"].ToString();
                txtTopicContent.Text = dr["TopicContent"].ToString();
                lblCreateDate.Text = dr["CreateDate"].ToString();
                lblUserIP.Text = dr["UserIP"].ToString();
            }
            dr.Close();
            dr.Dispose();
        }
    }
    protected void btnModify_Click(object sender, EventArgs e)
    {
        if (txtTopicTitle.Text.Trim() == "")
        {
            Response.Write("<script language=javascript>alert('标题不能为空!')</script>");
        }
        else if (txtTopicContent.Text.Trim() == "")
        {
            Response.Write("<script language=javascript>alert('内容不能为空!')</script>");
        }
        else
        {
            int iTopicID = Convert.ToInt32(Request.QueryString["TopicID"]);
            int iResult = topic.ModifyTopic(iTopicID, txtTopicTitle.Text, txtTopicContent.Text);
            if (iResult > 0)
            {
                Response.Write("<script language=javascript>alert('修改成功!')</script>");
                Response.Redirect("TopicList.aspx");
            }
            else
            {
                Response.Write("<script language=javascript>alert('修改失败!')</script>");
            }
        }
    }
    protected void btnGoBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("TopicList.aspx");
    }
}
